#include "log.h"
#include "SEGGER_RTT.h"



extern int SEGGER_RTT_vprintf(unsigned BufferIndex, const char * sFormat, va_list * pParamList);


// 输出16进制数组信息， 结尾换行
void log_array(uint8_t on, char* start,char *end,uint8_t * data, uint32_t len)
{
    uint32_t i =0;

    if(!on)
    {
        return;
    }

    if(len>500)
    {
        len = 500;
    }

    if(start != NULL)
      log_printf(on, start);
    
    for(i = 0;i<len;i++)
    {
        log_printf(on,"%02x ", data[i]);
    }
    
    if(end != NULL)
      log_printf(on, end);
}


void log_printf(uint8_t on, const char * sFormat, ...)
{    
    va_list ParamList;

    if(!on)
    {
      return;
    }

    va_start(ParamList, sFormat);
    SEGGER_RTT_vprintf(0, sFormat, &ParamList);
    va_end(ParamList);    
}


void log_printl(uint8_t on, const char * sFormat, ...)
{    
    va_list ParamList;

    if(!on)
    {
      return ;
    }
    va_start(ParamList, sFormat);
    SEGGER_RTT_vprintf(0, sFormat, &ParamList);
    va_end(ParamList);
    
    log_printf(on,"\r\n");
}